/**
 * 
 */
package com.wodsy.phoenix.apps.index.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.dubbo.common.json.JSON;
import com.wodsy.phoenix.dataobject.cms.vo.IdxAdPicResp;
import com.wodsy.phoenix.dataobject.cms.vo.IdxCustomizePicResp;
import com.wodsy.phoenix.dataobject.cms.vo.IdxHotGoodsRecResp;
import com.wodsy.phoenix.dataobject.cms.vo.IdxNewGoodsRecResp;
import com.wodsy.phoenix.dataobject.cms.vo.IdxShopRecResp;
import com.wodsy.phoenix.dataservice.cms.service.CmsHomePageBannerService;
import com.wodsy.phoenix.dataservice.cms.service.CmsHomePageCustomizePicService;
import com.wodsy.phoenix.dataservice.cms.service.CmsHomePageHotGoodsService;
import com.wodsy.phoenix.dataservice.cms.service.CmsHomePageNewGoodsService;
import com.wodsy.phoenix.dataservice.cms.service.CmsHomePageShopRecService;

/**
 * @author bryan
 *
 */
@RequestMapping("/index")
@Controller
public class HomePageIndexController {
	private Logger logger = LoggerFactory.getLogger(HomePageIndexController.class);
	@Autowired
	private CmsHomePageBannerService cmsHomePageBannerService;
	@Autowired
	private CmsHomePageCustomizePicService cmsHomePageCustomizePicService;
	@Autowired
	private CmsHomePageHotGoodsService cmsHomePageHotGoodsService;
	@Autowired
	private CmsHomePageNewGoodsService cmsHomePageNewGoodsService;
	@Autowired
	private CmsHomePageShopRecService cmsHomePageShopRecService;
	/**
     * 导向首页面
     *
     * @param request 请求
     * @return
     */
    @RequestMapping(value = "/index", method = RequestMethod.GET)
    public String index(HttpServletRequest request) {


        return "/index";
    }
    /**
	 * 获取在线bannerList(以weight升序排序)
	 */
    @RequestMapping(value = "/getOnlinePicBanner", method = RequestMethod.GET)
    @ResponseBody
	public List<IdxAdPicResp> getOnlinePicBanner(){
		List<IdxAdPicResp> tblist = cmsHomePageBannerService.getOnlinePicBanner();
		
		return tblist;
	}
    /**
	 * 获取在线goodsList(以weight升序排序)
	 */
    @RequestMapping(value = "/getOnlinePicNewGoods", method = RequestMethod.GET)
    @ResponseBody
	public List<IdxNewGoodsRecResp> getOnlinePicNewGoods(){
		List<IdxNewGoodsRecResp> tblist = cmsHomePageNewGoodsService.getOnlineNewGoodsRec();
		return tblist;
    }
    /**
	 * 获取在线goodsList(以weight升序排序)
	 */
    @RequestMapping(value = "/getOnlinePicHotGoods", method = RequestMethod.GET)
    @ResponseBody
    public List<IdxHotGoodsRecResp> getOnlinePicHotGoods(){
		List<IdxHotGoodsRecResp> tblist = cmsHomePageHotGoodsService.getOnlineHotGoodsRec();
		return tblist;
    }
    /**
	 * 获取在线customizePic
	 */
    @RequestMapping(value = "/getOnlinePicCustomizePic", method = RequestMethod.GET)
    @ResponseBody
	public IdxCustomizePicResp getOnlinePicCustomizePic(){
    	IdxCustomizePicResp tb = cmsHomePageCustomizePicService.getOnlineCustomizePicRec();
		return tb;
    }
    
    /**
	 * 获取在线shop
	 */
    @RequestMapping(value = "/getOnlinePicShopRecommended", method = RequestMethod.GET)
    @ResponseBody
	public IdxShopRecResp getOnlinePicShopRecommended(){
    	IdxShopRecResp tb = cmsHomePageShopRecService.getOnlineShopReccommendedRec();
		return tb;
    }
    
    /**
	 * 获取首页动态数据
	 */
    @RequestMapping(value = "/getHomePageData", method = RequestMethod.GET)
    @ResponseBody
	public Map<String, String> getHomePageData(){
    	HashMap<String, String> hMap = new HashMap<>();
    	
    	try {
    		List<IdxAdPicResp> bannertblist = cmsHomePageBannerService.getOnlinePicBanner();
        	List<IdxNewGoodsRecResp> newtblist = cmsHomePageNewGoodsService.getOnlineNewGoodsRec();
        	List<IdxHotGoodsRecResp> hottblist = cmsHomePageHotGoodsService.getOnlineHotGoodsRec();
        	IdxCustomizePicResp pictb = cmsHomePageCustomizePicService.getOnlineCustomizePicRec();
        	IdxShopRecResp shoptb = cmsHomePageShopRecService.getOnlineShopReccommendedRec();
        	
        	hMap.put("focusdate", "'"+JSON.json(bannertblist)+"'");
        	hMap.put("newGoods","'"+JSON.json(newtblist)+"'");
        	hMap.put("hotGoods","'"+JSON.json(hottblist)+"'");
        	hMap.put("customizePic","'"+JSON.json(pictb)+"'");
        	hMap.put("shopRec","'"+JSON.json(shoptb)+"'");
        	
        	//Scaffold_web_index.generateSourceFileFromTemplate("index.ftl", "index3", hMap);
        	
		} catch (Exception e) {
			// TODO: handle exception
		}
    	
		return hMap;
    }
    
}
